import Vue from "vue";
import Router from "vue-router";
const routerPush = Router.prototype.push;
Router.prototype.push = function push(location) {
  return routerPush.call(this, location).catch((error) => error);
};
Vue.use(Router);
import Layout from "@/layout"; //pc端
import mobile from "@/views/mobile";
// import store from '@/store'
// yingji
let http =
  process.env.NODE_ENV === "development"
    ? process.env.VUE_APP_BASE_API
    : window.location.href.slice(0, window.location.href.indexOf("/user"));

let isMobile;
if (
  navigator.userAgent.match(
    /(iPhone|iPod|Android|ios|iOS|iPad|Backerry|WebOS|Symbian|Windows Phone|Phone)/i
  )
) {
  isMobile = true;
} else {
  isMobile = false;
}
const pc = [
  {
    path: "/redirect",
    component: Layout,
    children: [
      {
        path: "/redirect/:path(.*)",
        component: () => import("@/views/admin/base/redirect"),
      },
    ],
  },

  {
    path: "/login",
    meta: {
      title: "登录",
    },
    hidden: true,
    component: () => import("@/views/admin/login/login"),
  },
  {
    path: "/wxbind",
    meta: {
      title: "微信登录",
    },
    hidden: true,
    component: () => import("@/views/admin/login/wxbind"),
  },
  {
    path: "/404",
    meta: {
      title: "404",
    },
    hidden: true,
    component: () => import("@/views/admin/base/404"),
  },
  {
    path: "/401",
    meta: {
      title: "401",
    },
    hidden: true,
    component: () => import("@/views/admin/base/401"),
  },
  {
    path: "/",
    redirect: "/dashboard",
    component: Layout,
    children: [
      {
        path: "dashboard",
        name: "Dashboard",
        meta: {
          title: "首页",
          icon: "icon-shouye",
          affix: true,
        },
        component: () => import("@/views/admin/index/index"),
        children: [],
      },
    ],
  },
  {
    path: "/infor",
    name: "infor",
    redirect: "noRedirect",
    component: Layout,
    children: [
      {
        path: "user",
        name: "user",
        meta: {
          title: "个人信息",
          icon: "icon-a-bianzu2",
        },
        component: () => import("@/views/pc/userInfor.vue"),
      },
    ],
  },
  {
    path: "/curriculum",
    name: "curriculum",
    redirect: "noRedirect",
    component: Layout,
    children: [
      {
        path: "index",
        name: "curriculumindex",
        meta: {
          title: "课程学习",
          icon: "icon-shuji_bookshelf",
          rouls: "3",
        },
        component: () => import("@/views/pc/curriculum2.vue"),
      },
      {
        path: "video",
        name: "video",
        hidden: true,
        meta: {
          title: "视频播放",
        },
        component: () => import("@/views/admin/components/video.vue"),
      },
      {
        path: "pdf",
        name: "pdf",
        hidden: true,
        meta: {
          title: "pdf文件",
        },
        component: () => import("@/views/admin/components/pdf.vue"),
      },
    ],
  },
  {
    path: "/practice",
    name: "practice",
    redirect: "noRedirect",
    component: Layout,
    children: [
      {
        path: "index",
        name: "index",
        meta: {
          title: "题库练习",
          icon: "icon-zhuanxiangrenwu",
          rouls: "0",
        },
        component: () => import("@/views/pc/practice.vue"),
      },
    ],
  },
  {
    path: "/simulation",
    name: "simulation",
    redirect: "noRedirect",
    component: Layout,
    hidden: false,
    children: [
      {
        path: "index",
        name: "simulationindex",
        meta: {
          title: "模拟考试",
          icon: "icon-monikaoshi-2",
          rouls: "1",
        },
        component: () => import("@/views/pc/simulation.vue"),
      },
    ],
  },
  {
    path: "/simulationzs",
    name: "simulationzs",
    redirect: "noRedirect",
    component: Layout,
    hidden: false,
    children: [
      {
        path: "index",
        name: "simulationzsindex",
        meta: {
          title: http.indexOf("yingji") != -1 ? "模拟练习" : "正式考试",
          icon: "icon-monikaoshi-2",
          rouls: "2",
        },
        component: () => import("@/views/pc/simulationzs.vue"),
      },
    ],
  },

  {
    path: "/mysjList",
    name: "mysjList",
    component: Layout,
    children: [
      {
        path: "index",
        name: "mysjListIndex",
        meta: {
          title: "我的试卷",
        },
        hidden: true,
        component: () => import("@/views/pc/components/mysjList.vue"),
      },
    ],
  },
  {
    path: "/mysjListzs",
    name: "mysjListzs",
    component: Layout,
    children: [
      {
        path: "index",
        name: "mysjListzsIndex",
        meta: {
          title: "我的试卷",
        },
        hidden: true,
        component: () => import("@/views/pc/components/mysjListzs.vue"),
      },
    ],
  },
  {
    path: "/record",
    name: "record",
    redirect: "/record/index",
    component: Layout,
    children: [
      {
        path: "index",
        name: "recordindex",
        meta: {
          title: "学习记录",
        },
        hidden: true,
        component: () => import("@/views/pc/record"),
      },
    ],
  },
  {
    path: "/questionsSearch",
    name: "questionsSearch",
    redirect: "noRedirect",
    component: Layout,
    children: [
      {
        path: "index",
        name: "questionsSearchindex",
        meta: {
          title: "试题搜索",
        },
        hidden: true,
        component: () => import("@/views/pc/questionsSearch"),
      },
    ],
  },
  {
    path: "/statistics",
    name: "statistics",
    redirect: "noRedirect",
    component: Layout,
    children: [
      {
        path: "index",
        name: "statisticsindex",
        meta: {
          title: "学习统计",
          icon: "icon-tongji-2",
        },
        component: () => import("@/views/pc/statistics.vue"),
      },
    ],
  },
  {
    path: "/feedback",
    name: "feedback",
    redirect: "noRedirect",
    component: Layout,
    children: [
      {
        path: "index",
        name: "feedback",
        meta: {
          title: "问题反馈",
          icon: "icon-zhuanxiangrenwu",
        },
        component: () => import("@/views/pc/feedback"),
      },
      {
        path: "feedbackDetail",
        name: "feedbackDetail",
        meta: {
          title: "问题反馈详情",
          icon: "icon-zhuanxiangrenwu",
        },
        hidden: true,
        component: () => import("@/views/pc/feedback/details"),
      },
    ],
  },
  {
    path: "/exam",
    name: "exam",
    hidden: true,
    component: () => import("@/views/pc/components"),
  },
  {
    path: "/simulationExam",
    name: "simulationExam",
    hidden: true,
    component: () => import("@/views/pc/components/simulation"),
  },
  {
    path: "/simulationzsExam",
    name: "simulationzsExam",
    hidden: true,
    component: () => import("@/views/pc/components/simulationZs"),
  },
  {
    path: "/rengongm",
    name: "rengongm",
    hidden: true,
    component: () => import("@/views/pc/components/rengong"),
  },
  {
    path: "/classroomTest",
    name: "classroomTest",
    hidden: true,
    component: () => import("@/views/pc/components/classroomTest"),
  },
  {
    path: "/classroomVideoTest",
    name: "classroomVideoTest",
    hidden: true,
    component: () => import("@/views/pc/components/classroomVideoTest"),
  },
  {
    path: "/face",
    name: "face",
    hidden: true,
    component: () => import("@/components/PcFace"),
  },

  // {
  //   path: '/home',
  //   redirect: '/',
  // },
  // {
  //   path: '/mine',
  //   redirect: '/',
  // },
  // {
  //   path: '/study',
  //   redirect: '/',
  // },
  {
    path: "*",
    redirect: "/404",
    hidden: true,
  },
];
const Mobile = [
  {
    path: "/404",
    meta: {
      title: "404",
    },
    hidden: true,
    component: () => import("@/views/admin/base/mobile404"),
  },
  {
    path: "/401",
    meta: {
      title: "401",
    },
    hidden: true,
    component: () => import("@/views/admin/base/mobile401"),
  },
  // {
  //   path: '/401',
  //   meta: {
  //     title: '401'
  //   },
  //   hidden: true,
  //   component: () => import('@/views/admin/base/401')
  // },
  {
    path: "/wxbind",
    meta: {
      title: "绑定",
    },
    hidden: true,
    component: () => import("@/views/admin/login/wxbind"),
  },
  // {
  //   path: '/login',
  //   meta: {
  //     title: '登录'
  //   },
  //   hidden: true,
  //   component: () => import('@/views/admin/login/mobile')
  // },
  {
    path: "/wxlogin",
    meta: {
      title: "登录",
    },
    hidden: true,
    component: () => import("@/views/admin/login/wxlogin"),
  },
  {
    path: "/",
    redirect: "/home",
    component: mobile,
    children: [
      {
        path: "home",
        name: "home",
        component: () => import("@/views/mobile/home/index"),
      },
      {
        path: "knowlage",
        name: "knowlage",
        component: () => import("@/views/mobile/home/knowlage"),
      },
      {
        path: "mine",
        name: "mine",
        component: () => import("@/views/mobile/mine/index"),
      },
      {
        path: "practice",
        name: "practice",
        component: () => import("@/views/mobile/practice/index"),
      },

      {
        path: "study",
        name: "study",
        component: () => import("@/views/mobile/study/index"),
      },
    ],
  },

  {
    path: "/classExam",
    name: "classExam",
    hidden: true,
    component: () => import("@/views/mobile/study/components/components"),
  },

  {
    path: "/videoPractice",
    name: "videoPractice",
    hidden: true,
    component: () => import("@/views/mobile/study/components/videoPractice"),
  },
  // {
  //   path: "/videoPracticeResult",
  //   name: "videoPracticeResult",
  //   hidden: true,
  //   component: () => import("@/views/mobile/study/components/videoPractice"),
  // },

  {
    path: "/video",
    name: "video",
    hidden: true,
    component: () => import("@/views/mobile/study/components/mobileVideo"),
  },
  {
    path: "/PDF",
    name: "PDF",
    hidden: true,
    component: () => import("@/views/mobile/study/components/mobilePDF"),
  },
  {
    path: "/exam",
    name: "exam",
    hidden: true,
    component: () => import("@/views/mobile/practice/components"),
  },
  {
    path: "/examVideo",
    name: "examVideo",
    hidden: true,
    component: () =>
      import("@/views/mobile/study/components/videoPractice/exam"),
  },
  {
    path: "/feedback",
    name: "feedback",
    hidden: true,
    component: () => import("@/views/mobile/practice/components/feedback.vue"),
  },
  {
    path: "/feedbackList",
    name: "feedbackList",
    hidden: true,
    component: () =>
      import("@/views/mobile/practice/components/feedbackList.vue"),
  },
  {
    path: "/feedbackCheck",
    name: "feedbackCheck",
    hidden: true,
    component: () =>
      import("@/views/mobile/practice/components/feedbackCheck.vue"),
  },
  {
    path: "/result",
    name: "result",
    hidden: true,
    component: () => import("@/views/mobile/practice/components/result"),
  },
  {
    path: "/results",
    name: "results",
    hidden: true,
    component: () =>
      import("@/views/mobile/study/components/components/result"),
  },
  {
    path: "/resultVideo",
    name: "resultVideo",
    hidden: true,
    component: () =>
      import("@/views/mobile/study/components/videoPractice/result"),
  },
  {
    path: "/record",
    name: "record",
    hidden: true,
    component: () => import("@/views/mobile/home/record"),
  },
  {
    path: "/annex",
    name: "annex",
    hidden: true,
    component: () => import("@/views/mobile/home/annex"),
  },
  {
    path: "/evaluate",
    name: "evaluate",
    hidden: true,
    component: () => import("@/views/mobile/home/evaluate/huacong.vue"),
  },
  {
    path: "/evaluateTaiHua",
    name: "evaluateTaiHua",
    hidden: true,
    component: () => import("@/views/mobile/home/evaluate/taihua.vue"),
  },
  {
    path: "/evaluateIndex",
    name: "evaluateIndex",
    hidden: true,
    component: () => import("@/views/mobile/home/evaluate/index.vue"),
  },
  {
    path: "/MyExam",
    name: "MyExam",
    hidden: true,
    component: () => import("@/views/mobile/practice/MyExam"),
  },
  {
    path: "/MyExamzs",
    name: "MyExamzs",
    hidden: true,
    component: () => import("@/views/mobile/practice/MyExamzs"),
  },
  {
    path: "/statistics",
    name: "statistics",
    hidden: true,
    component: () => import("@/views/mobile/home/statistics"),
  },
  {
    path: "/questionsSearch",
    name: "questionsSearch",
    hidden: true,
    component: () => import("@/views/mobile/home/questionsSearch"),
  },
  {
    path: "/SCstudy",
    name: "SCstudy",
    component: () => import("@/views/mobile/SCstudy/index"),
  },
  {
    path: "/Invoice",
    name: "Invoice",
    component: () => import("@/views/mobile/Invoice/index"),
  },
  {
    path: "/loading",
    hidden: true,
    meta: {
      title: "loading",
    },
    component: () => import("@/views/admin/login/loading"),
  },
  {
    path: "/face",
    name: "face",
    hidden: true,
    meta: {
      title: "face",
    },
    component: () => import("@/components/Face/photo.vue"),
  },
  {
    path: "/user",
    name: "user",
    meta: {
      title: "个人信息",
    },
    component: () => import("@/views/mobile/mine/user.vue"),
  },
  {
    path: "*",
    redirect: "/",
    hidden: true,
  },
];
export const constantRoutes = isMobile ? Mobile : pc;
const createRouter = () =>
  new Router({
    // mode: 'history', // 去掉url中的#号，需要服务器支持
    scrollBehavior: () => ({
      y: 0,
    }),
    routes: constantRoutes,
  });

const router = createRouter();

export function resetRouter() {
  const newRouter = createRouter();
  router.matcher = newRouter.matcher; // reset router
}

export default router;
